package com.learn;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.core.env.Environment;
import org.springframework.stereotype.Component;

/**
 * 获取配置值得方法
 * 默认获取application.properties文件得属性，可以通过--spring.config.name来修改
 * 默认路径为根目录或者classpath:config/下可以通过--spring.config.location来指定
 * @author Romanceling
 *
 */
@Component
public class UserConfige {

	@Autowired
	private Environment env;
	
	@Value("${local.port}")
	private String localPort;
	
	//默认值9090
	@Value("${tomcat.port:9090}")
	private String tomcatPort;
	
	public void show(){
		System.out.println("local.ip = "+ env.getProperty("local.ip"));
		System.out.println("local.port = "+ localPort);
		
		System.out.println("name = "+ env.getProperty("name"));
		System.out.println("app.name = "+ env.getProperty("app.name"));
		
		System.out.println("tomcatPort = "+tomcatPort);
	}
}
